package cn.sfrog.project.biz.admin.controller;

import cn.sfrog.common.annotation.Log;
import cn.sfrog.common.annotation.RepeatSubmit;
import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.AjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.enums.BusinessType;
import cn.sfrog.common.utils.poi.ExcelUtil;
import cn.sfrog.project.biz.admin.domain.vo.BizServiceOrderDataUploadFormVO;
import cn.sfrog.project.biz.admin.domain.vo.BizServiceOrderDataUploadQueryVO;
import cn.sfrog.project.biz.admin.domain.vo.BizServiceOrderDataUploadVO;
import cn.sfrog.project.biz.admin.service.IBizServiceOrderDataUploadService;
import cn.sfrog.system.domain.vo.BizStatusChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "服务订单资料上传接口")
@RestController
@RequestMapping("/biz/dataUpload")
public class BizServiceOrderDataUploadController extends BaseController {
    @Resource
    private IBizServiceOrderDataUploadService bizServiceOrderDataUploadService;

    /**
     * 查询服务订单资料上传列表
     */
    @ApiOperation("查询列表")
    @PreAuthorize("@ss.hasPermi('biz:dataUpload:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizServiceOrderDataUploadQueryVO queryVO) {
        startPage();
        List<BizServiceOrderDataUploadVO> list = bizServiceOrderDataUploadService.selectBizServiceOrderDataUploadList(queryVO);
        return getDataTable(list);
    }

    /**
     * 导出服务订单资料上传列表
     */
    @ApiOperation("导出")
    @PreAuthorize("@ss.hasPermi('biz:dataUpload:export')")
    @Log(title = "服务订单资料上传", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizServiceOrderDataUploadQueryVO query) {
        List<BizServiceOrderDataUploadVO> list = bizServiceOrderDataUploadService.selectBizServiceOrderDataUploadList(query);
        ExcelUtil<BizServiceOrderDataUploadVO> util = new ExcelUtil<BizServiceOrderDataUploadVO>(BizServiceOrderDataUploadVO.class);
        util.exportExcel(response, list, "服务订单资料上传数据");
    }

    /**
     * 获取服务订单资料上传详细信息
     */
    @ApiOperation("获取详情")
    @PreAuthorize("@ss.hasPermi('biz:dataUpload:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(bizServiceOrderDataUploadService.selectBizServiceOrderDataUploadById(id));
    }

    /**
     * 新增服务订单资料上传
     */
    @ApiOperation("新增")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:dataUpload:add')")
    @Log(title = "服务订单资料上传", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizServiceOrderDataUploadFormVO form) {
        return toAjax(bizServiceOrderDataUploadService.insertBizServiceOrderDataUpload(form));
    }

    /**
     * 修改服务订单资料上传
     */
    @ApiOperation("修改")
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('biz:dataUpload:edit')")
    @Log(title = "服务订单资料上传", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizServiceOrderDataUploadFormVO form) {
        return toAjax(bizServiceOrderDataUploadService.updateBizServiceOrderDataUpload(form));
    }

    /**
     * 删除服务订单资料上传
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('biz:dataUpload:remove')")
    @Log(title = "服务订单资料上传", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bizServiceOrderDataUploadService.deleteBizServiceOrderDataUploadByIds(ids));
    }

    /**
     * 更改状态服务订单资料上传
     */
    @ApiOperation("更改状态")
    @PreAuthorize("@ss.hasPermi('biz:dataUpload:changeStatus')")
    @Log(title = "服务订单资料上传", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody @Valid BizStatusChangeVO vo) {
        return AjaxResult.success(bizServiceOrderDataUploadService.changeStatus(vo));
    }
}
